generic-array
This crate implements generic array types for Rust.
Requires minumum Rust version of 1.36.0, or 1.41.0 for From<[T; N]>
implementations
Usage
The Rust arrays [T; N]
are problematic in that they can't be used generically with respect to N
, so for example this won't work:
generic-array defines a new trait ArrayLength<T>
and a struct GenericArray<T, N: ArrayLength<T>>
, which let the above be implemented as:
The ArrayLength<T>
trait is implemented by default for unsigned integer types from typenum crate:
use U5;
For example, GenericArray<T, U5>
would work almost like [T; 5]
:
use U5;
In version 0.1.1 an arr!
macro was introduced, allowing for creation of arrays as shown below:
let array = arr!;
assert_eq!;